package page;

import java.util.List;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;

import app.WebApp;
import dao.FlightDao;
import entity.Flight;

public class DispatcherFlightListPage extends WebPage {

	public DispatcherFlightListPage() {
		super();
		final FlightDao flightDao = new FlightDao(WebApp.DATA_XML_FOLDER);
		final List<Flight> allFlight = flightDao.getAll();
		add(new DataView<Flight>("table-rows", new ListDataProvider<Flight>(allFlight)) {
			@Override
			protected void populateItem(final Item<Flight> item) {
				final Flight flight = item.getModelObject();
				item.add(new Label("route", flight.GetRoute()));
				item.add(new Label("time", flight.GetTime()));
				item.add(new Label("plane", flight.GetPlane()));
				item.add(new Label("firstpilot", flight.GetFirstpilot()));
				item.add(new Label("copilot", flight.GetCopilot()));
				item.add(new Label("navigator", flight.GetNavigator()));
				item.add(new Label("operator", flight.GetRadiooperator()));
				item.add(new Label("firststew", flight.GetFirststewardess()));
				item.add(new Label("secondstew", flight.GetSecondstewardess()));
				item.add(new Label("thirdstew", flight.GetThirdstewardess()));
				item.add(new Link("editLink") {
					@Override
					public void onClick() {
						setResponsePage(new EditFlightPage(flight));
						flightDao.delete(flight.getId());
					}
				});
			}
		});	
		add(new Link("logout") {
			@Override
			public void onClick() {
				setResponsePage(new AllFlightListPage());
			}
		});
	}
}

